import { ISchema } from '@formily/react'
import {
  ColumnSetter,
  ActionColumnFieldSetter,
  ExpressionDialogSetter,
  ToolBarRenderSetter,
  RowSelectionSetter,
} from '@designable/formily-setters'
import { ReactionsSetter } from '@designable/formily-setters'
import { FormItemSwitcher } from '../common/FormItemSwitcher'

export const ProTable: ISchema = {
  type: 'object',
  properties: {
    'field-group': {
      type: 'void',
      'x-component': 'CollapseItem',
      properties: {
        name: {
          type: 'string',
          'x-decorator': 'FormItem',
          'x-component': 'Input',
        },
        title: {
          type: 'string',
          'x-decorator': 'FormItem',
          'x-component': 'Input',
          'x-reactions': {
            fulfill: {
              state: {
                hidden: '{{$form.values["x-decorator"] !== "FormItem"}}',
              },
            },
          },
        },
        description: {
          type: 'string',
          'x-decorator': 'FormItem',
          'x-component': 'Input.TextArea',
          'x-reactions': {
            fulfill: {
              state: {
                hidden: '{{$form.values["x-decorator"] !== "FormItem"}}',
              },
            },
          },
        },
        'x-display': {
          type: 'string',
          enum: ['visible', 'hidden', 'none', ''],
          'x-decorator': 'FormItem',
          'x-component': 'Select',
          'x-component-props': {
            defaultValue: 'visible',
          },
        },
        'x-pattern': {
          type: 'string',
          enum: ['editable', 'disabled', 'readOnly', 'readPretty', ''],
          'x-decorator': 'FormItem',
          'x-component': 'Select',
          'x-component-props': {
            defaultValue: 'editable',
          },
        },
        'x-reactions': {
          'x-decorator': 'FormItem',
          'x-component': ReactionsSetter,
        },
        'x-decorator': {
          type: 'string',
          'x-decorator': 'FormItem',
          'x-component': FormItemSwitcher,
        },
      },
    },
    'dataSource-group': {
      type: 'void',
      'x-component': 'CollapseItem',
      properties: {
        'x-component-props': {
          type: 'object',
          properties: {
            request: {
              'x-decorator': 'FormItem',
              'x-component': ExpressionDialogSetter,
            },
            rowKey: {
              type: 'string',
              'x-decorator': 'FormItem',
              'x-component': 'Input',
            },
          },
        },
      },
    },
    'column-group': {
      type: 'void',
      'x-component': 'CollapseItem',
      properties: {
        'x-component-props': {
          type: 'object',
          properties: {
            columns: {
              type: 'array',
              'x-component': ColumnSetter,
            },
          },
        },
      },
    },
    'action-column-group': {
      type: 'void',
      'x-component': 'CollapseItem',
      properties: {
        'x-component-props': {
          type: 'object',
          properties: {
            action: {
              type: 'object',
              properties: {
                title: {
                  type: 'string',
                  'x-decorator': 'FormItem',
                  'x-component': 'Input',
                  'x-component-props': {
                    defaultValue: '操作',
                  },
                },
                width: {
                  type: 'string',
                  'x-decorator': 'FormItem',
                  'x-component': 'NumberPicker',
                  'x-component-props': {
                    addonAfter: 'px',
                  },
                },
                fixed: {
                  type: 'string',
                  'x-decorator': 'FormItem',
                  'x-component': 'Radio.Group',
                  'x-component-props': {
                    optionType: 'button',
                    options: [
                      {
                        label: 'left',
                        value: 'left',
                      },
                      {
                        label: 'center',
                        value: '',
                      },
                      {
                        label: 'right',
                        value: 'right',
                      },
                    ],
                  },
                },
                showLen: {
                  type: 'string',
                  'x-decorator': 'FormItem',
                  'x-component': 'NumberPicker',
                  'x-component-props': {
                    defaultValue: 3,
                  },
                },
                buttons: {
                  type: 'array',
                  'x-component': ActionColumnFieldSetter,
                },
              },
            },
          },
        },
      },
    },
    'toolbar-group': {
      type: 'void',
      'x-component': 'CollapseItem',
      properties: {
        'x-component-props': {
          type: 'object',
          properties: {
            tabs: {
              'x-decorator': 'FormItem',
              'x-component': ExpressionDialogSetter,
            },
            toolBarRender: {
              type: 'array',
              'x-component': ToolBarRenderSetter,
            },
          },
        },
      },
    },
    'rowSelection-group': {
      type: 'void',
      'x-component': 'CollapseItem',
      properties: {
        'x-component-props': {
          type: 'object',
          properties: {
            rowSelection: {
              type: 'object',
              'x-component': RowSelectionSetter,
            },
          },
        },
      },
    },
    'pagination-group': {
      type: 'void',
      'x-component': 'CollapseItem',
      properties: {
        'x-component-props': {
          type: 'object',
          properties: {
            pagination: {
              type: 'object',
              properties: {
                enabled: {
                  type: 'boolean',
                  'x-decorator': 'FormItem',
                  'x-component': 'Switch',
                  'x-component-props': {
                    defaultChecked: true,
                  },
                },
                current: {
                  type: 'number',
                  'x-decorator': 'FormItem',
                  'x-component': 'NumberPicker',
                  'x-component-props': {
                    defaultValue: 1,
                  },
                },
                pageSize: {
                  type: 'number',
                  'x-decorator': 'FormItem',
                  'x-component': 'NumberPicker',
                  'x-component-props': {
                    defaultValue: 10,
                  },
                },
                defaultPageSize: {
                  type: 'number',
                  'x-decorator': 'FormItem',
                  'x-component': 'NumberPicker',
                  'x-component-props': {
                    defaultValue: 10,
                  },
                },
                showSizeChanger: {
                  type: 'boolean',
                  'x-decorator': 'FormItem',
                  'x-component': 'Switch',
                  'x-component-props': {
                    defaultChecked: true,
                  },
                },
                showQuickJumper: {
                  type: 'boolean',
                  'x-decorator': 'FormItem',
                  'x-component': 'Switch',
                  'x-component-props': {
                    defaultChecked: true,
                  },
                },
                showTotal: {
                  type: 'boolean',
                  'x-decorator': 'FormItem',
                  'x-component': 'Switch',
                  'x-component-props': {
                    defaultChecked: false,
                  },
                },
                size: {
                  type: 'string',
                  enum: ['default', 'small'],
                  'x-decorator': 'FormItem',
                  'x-component': 'Select',
                  'x-component-props': {
                    defaultValue: 'default',
                  },
                },
                position: {
                  type: 'string',
                  enum: [
                    'topLeft',
                    'topCenter',
                    'topRight',
                    'bottomLeft',
                    'bottomCenter',
                    'bottomRight',
                  ],
                  'x-decorator': 'FormItem',
                  'x-component': 'Select',
                  'x-component-props': {
                    defaultValue: 'bottomRight',
                  },
                },
                responsive: {
                  type: 'boolean',
                  'x-decorator': 'FormItem',
                  'x-component': 'Switch',
                  'x-component-props': {
                    defaultChecked: true,
                  },
                },
                hideOnSinglePage: {
                  type: 'boolean',
                  'x-decorator': 'FormItem',
                  'x-component': 'Switch',
                  'x-component-props': {
                    defaultChecked: false,
                  },
                },
                simple: {
                  type: 'boolean',
                  'x-decorator': 'FormItem',
                  'x-component': 'Switch',
                  'x-component-props': {
                    defaultChecked: false,
                  },
                },
              },
            },
          },
        },
      },
    },
    'scroll-group': {
      type: 'void',
      'x-component': 'CollapseItem',
      properties: {
        'x-component-props': {
          type: 'object',
          properties: {
            scroll: {
              type: 'object',
              properties: {
                x: {
                  type: 'number',
                  'x-decorator': 'FormItem',
                  'x-component': 'NumberPicker',
                  'x-component-props': {
                    addonAfter: 'px',
                    defaultValue: 2000,
                  },
                },
                y: {
                  type: 'number',
                  'x-decorator': 'FormItem',
                  'x-component': 'NumberPicker',
                  'x-component-props': {
                    addonAfter: 'px',
                  },
                },
              },
            },
          },
        },
      },
    },
  },
}
